﻿using System;
using System.Diagnostics;

namespace Bing
{
    /// <summary>
    /// Contains parameters for a request to the Ad <see cref="ApiHelper.SourceType"/>.
    /// </summary>
    [DebuggerDisplay("PropertyId:{PropertyId}, MainAds:{MlAdcount}, Sidebar:{SbAdCount}")]
    public class AdRequest: IBingRequest
    {
        /// <summary>
        /// Gets or sets the number of the page on which you want an advertisement to appear.
        /// </summary>
        /// <value>The number of the page on which you want an advertisement to appear.</value>
        /// <remarks>If an application displays five pages of search results, then when the ads for the first page are retrieved, PageNumber=0, for the next page, PageNumber=1, and so on</remarks>
        public UInt32 PageNumber { get; set; }

        /// <summary>
        /// Gets or sets Number of mainline advertisements requested..
        /// </summary>
        /// <value>Number of mainline advertisements requested.</value>
        /// <remarks>If no value is specified, the default value is 3. </remarks>
        public UInt32 MlAdcount { get; set; }

        /// <summary>
        /// Gets or sets the number of sidebar advertisements requested.
        /// </summary>
        /// <value>Number of sidebar advertisements requested.</value>
        /// <remarks>
        /// If a value is not specified for this parameter, the default is 5.<br />
        /// The total value of <b><see cref="MlAdcount"/></b>+<b>SbAdCount</b> cannot exceed 25.
        /// </remarks>
        public UInt32 SbAdCount { get; set; }

        /// <summary>
        /// Gets or sets ad unit identifier for a request.
        /// </summary>
        /// <value>Ad unit identifier for a request.</value>
        /// <remarks>On a web page or other property, an ad unit is a space set aside where ads will appear. Ad units can contain one or more ads; for example, the banner space across the top of a page.</remarks>
        public UInt32 AdUnitId { get; set; }
        
        /// <summary>
        /// Gets or sets the channel identifier for this request..
        /// </summary>
        /// <value>Channel identifier for this request.</value>
        /// <remarks>Channels are a reporting feature. You create your own channels, and use them to monitor the performance of specific pages and ad units. Creating channels is optional, and does not affect your revenue or how your ads display, but gives you much more specific data in your reports.</remarks>
        public string ChannelId { get; set; }

        /// <summary>
        /// Gets or sets the property identifier for this request.
        /// </summary>
        /// <value>Property identifier for this request.</value>
        /// <remarks>A <b><i>property</i></b> is a space on a web page, RSS feed, software screen, or other published medium where advertisements can appear.</remarks>
        public UInt32 PropertyId { get; set; }

        /// <summary>
        /// Creates the query string for the API call.
        /// </summary>
        /// <returns>The query string to append to the call.</returns>
        public string ToQueryString()
        {
            string request = string.Format("&Ad.PageNumber={0}", PageNumber);
            if (MlAdcount > 0 || SbAdCount > 0)
            {
                request += string.Format("&Ad.MlAdCount={0}", MlAdcount);
                request += string.Format("&Ad.SbAdCount={0}", SbAdCount);
            }
            request += string.Format("&Ad.PropertyId={0}", PropertyId);
            request += string.Format("&Ad.AdUnitId={0}", AdUnitId);
            request += string.Format("&Ad.ChannelId={0}", ChannelId);
            return request;
        }
    }
}
